<?php
/*
*
* cms.Archives  内容发布系统 自定义表单
*
* =========================================================
* 零起飞网络 - 专注于网站建设服务和行业系统开发
* 以质量求生存，以服务谋发展，以信誉创品牌 !
* ----------------------------------------------
* @copyright	Copyright (C) 2017-2018 07FLY Network Technology Co,LTD (www.07FLY.com) All rights reserved.
* @license    For licensing, see LICENSE.html or http://www.07fly.xyz/crm/license
* @author ：kfrs <goodkfrs@QQ.com> 574249366
* @version ：1.0
* @link ：http://www.07fly.xyz
*/

namespace app\workflow\controller;

use think\db;

/**
 * 自定义表单数据=》控制器
 */
class WorkflowDiyData extends WorkflowBase
{

    private $tableinfo = [];
    private $tablename = '';
    private $diy_form_id = '';

    /**
     * 析构函数
     */
    function __construct()
    {
        // 执行父类构造方法
        parent::__construct();

        if (!empty($this->param['diy_form_id'])) {
            $this->assign('diy_form_id', $this->param['diy_form_id']);
            $this->tableinfo = $this->logicWorkflowDiyForm->getWorkflowDiyFormInfo(['id' => $this->param['diy_form_id']]);
            $this->tablename = $this->tableinfo['ext_table'];
            $this->diy_form_id = $this->param['diy_form_id'];
        } else {
            throw_response_error('选择表单');
        }

        if (!empty($this->param['listtype'])) {
            $this->assign('listtype', $this->param['listtype']);
        } else {
            $this->assign('listtype', '');
        }
    }

    /**
     * 自定义表单数据=》列表
     */
    public function show()
    {
        if (IS_POST) {
            $list = $this->logicWorkflowDiyData->getWorkflowDiyDataList($this->param);
            return $list;
        }

        //自定义字段，列表展示
        $field_list = $this->logicWorkflowDiyField->getFieldExtFields($this->param['diy_form_id'], 'list');

        $this->assign('field_list', $field_list);

        return $this->fetch('show');
    }

    /**
     * 自定义表单数据=》添加
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicWorkflowDiyData->workflowDiyDataAdd($this->param));


        $this->assign('info', $this->tableinfo);

        $fieldhtml = $this->logicWorkflowDiyField->getFieldExtHtml($this->param['diy_form_id']);

        $this->assign('fieldhtml', $fieldhtml);

        return $this->fetch('add');
    }

    //自定义表单数据=>修改
    public function edit()
    {

        IS_POST && $this->jump($this->logicWorkflowDiyData->workflowDiyDataEdit($this->param));

        //表单数据信息
        $info = $this->logicWorkflowDiyData->getWorkflowDiyDataInfo($this->param);
        $this->assign('info', $info);

        //扩展字段信息=》回显
        $fieldhtml = $this->logicWorkflowDiyField->getFieldExtHtml($this->param['diy_form_id'], $info);
        $this->assign('fieldhtml', $fieldhtml);

        return $this->fetch('edit');
    }


    /**
     * 自定义表单数据=》删除
     */
    public function del()
    {
        $this->jump($this->logicWorkflowDiyData->workflowDiyDataDel($this->param));
    }

    /**
     * 自定义表单数据=》详细数据
     */
    public function detail()
    {

        //表单数据信息
        $info = $this->logicWorkflowDiyData->getWorkflowDiyDataInfo($this->param);
        $this->assign('info', $info);

        $this->assign('table', $this->tableinfo);

        //自定义字段，列表展示
        $field_list = $this->logicWorkflowDiyField->getFieldExtFields($this->param['diy_form_id'], 'visible');
        $this->assign('field_list', $field_list);

        $this->assign('info', $info);
        return $this->fetch('detail');
    }

    /**
     * 自定义表单数据=》提交审批
     */
    public function audit_send()
    {
        IS_POST && $this->jump($this->logicWorkflowDiyData->setWorkflowDiyDataAuditSend($this->param));

        //内部接口调用=》提交看审批
        $postdata['business_type'] = $this->tablename;
        $rpcurl = url('workflow/rpc.RpcApi/getWorkFlowList', $postdata);
        $res = httpRpc($rpcurl);
        $audit_workflow_list = [];
        if ($res['code'] == 1) {
            $audit_workflow_list = $res['data'];
        }
        $this->assign('id', $this->param['id']);
        $this->assign('audit_workflow_list', $audit_workflow_list);

        return $this->fetch('audit_send');

    }

    /**
     * 自定义表单数据=》取消审核
     */
    public function audit_cancel()
    {
        $this->jump($this->logicWorkflowDiyData->setAuditCancel($this->param));
    }

    /**
     * 自定义表单数据=》审核详细
     */
    public function audit_detail()
    {
        //内部接口调用=》提交看审批
        $intedata['business_type'] = $this->tablename;
        $intedata['business_id'] = $this->param['id'];
        $rpcurl = url('workflow/rpc.RpcApi/getWorkflowBusinessInfo', $intedata);
        $res = httpRpc($rpcurl);
        $this->assign('info', $res['data']);
        return $this->fetch('audit_detail');
    }

}
